home *** CD-ROM | disk | FTP | other *** search
Text File | 1995-01-26 | 11.7 KB | 488 lines | [TEXT/KAHL] |
- * ***
- * Methods for an object inspector
- *
- * Julian Barkway (c) October 1994. All rights reserved.
- *
- * v3.1.3 Initial release.
- *
- * ***
- Class ListPane SelectListPane theList
- Class InspectorView Object iWindow namePane valuePane nameList
- Class ObjectInspector InspectorView theObject namePMenu valuePMenu
- Class ClassHierarchyInspector InspectorView theClass selectedClass valuePMenu
- Class CollectionInspector InspectorView theCollection namePMenu
- Class ArrayInspector CollectionInspector
-
- Methods Object 'inspecting'
- inspect
- ObjectInspector new; inspect: self
- ]
-
-
- Methods Class 'inspecting'
- inspect
- ClassHierarchyInspector new; inspect: self
- ]
-
- Methods Array 'modifying'
- removeValues: aConditionBlock
- | list |
- list <- List new.
- self do: [ :x |
- (aConditionBlock value: x ) ifFalse: [
- list addLast: x
- ]
- ].
- self become: (list asArray)
- ]
-
- Methods Class 'modifying'
- addInstanceVariable: aSymbol
- | s |
- variables isNil ifTrue: [
- variables <- Array new: 0
- ].
- s <- variables select: [ :i | aSymbol = i ].
- (s size > 0) ifTrue: [
- ^ true
- ]
- ifFalse: [
- variables <- variables grow: aSymbol.
- ^ false
- ]
- |
- removeInstanceVariable: aSymbol
- | s |
- s <- variables select: [ :i | aSymbol = i ].
- (s size = 0) ifTrue: [
- ^ true
- ]
- ifFalse: [
- j <- (variables size - 1).
- (j = 0) ifTrue: [
- variables <- nil
- ]
- ifFalse: [
- variables removeValues: [ :x | aSymbol = x ]
- ].
- ^ false
- ]
- ]
-
- Methods IndexedCollection 'inspecting'
- inspect
- CollectionInspector new; inspect: self
- ]
-
- Methods Array 'inspecting'
- inspect
- ArrayInspector new; inspect: self
- ]
-
- Methods Dictionary 'displaying'
- printString | s |
- s <- self class printString , ' ('.
- self binaryDo: [:x :y | s <- s , (x printString) , ' -> ',
- (y printString) , newLine ].
- s <- s , ')'.
- ^ s
- ]
-
- Methods Link 'accessing'
- key
- ^ key
- ]
-
- Methods List 'assigning'
- links: aLink
- links <- aLink
- |
- addFirstLink: aLink
- (links notNil) ifTrue: [
- aLink link: links.
- links <- aLink
- ]
- ifFalse: [
- aLink link: nil.
- links <- aLink.
- listEnd <- links
- ]
- |
- addLastLink: aLink
- (links isNil)
- ifTrue: [ self addFirstLink: aLink ]
- ifFalse: [
- listEnd link: aLink.
- listEnd <- listEnd next
- ]
- ]
-
- Methods List 'accessing'
- newDo: aBlock
- | aLink |
- " For each link, perform aBlock using the link as an argument "
- aLink <- links.
- [ aLink notNil ] whileTrue: [
- aBlock value: aLink.
- aLink <- aLink next
- ]
- ]
-
- Methods ListPane 'all'
- " Implements a pane allowing selections from an ordered list "
- list: aList
- theList <- aList.
- |
- list
- ^ theList
- |
- setText | t |
- t <- '------------------' , newLine.
- (theList links) binaryDo: [:k :v |
- t <- t , k , newLine
- ].
- t <- t , '------------------'.
- self clearAllText.
- self text: t
- |
- getSelectedItem
- ^ theList links at: (self getSelectedKey) ifAbsent: [ ^ nil ].
- |
- getSelectedKey | t |
- t <- self selectedText.
- ( (t = '------------------') or:
- [t = ('------------------' , newLine) ]) ifTrue: [
- ^ nil
- ].
- ^ t copyFrom: 1 to: ((t size) - 1).
- ]
-
- Methods InspectorView 'all'
- makeWindow: aTitle
- | maxW maxH posX posY centreScreen origin |
- maxW <- (smalltalk getMaxScreenArea) right.
- maxH <- (smalltalk getMaxScreenArea) bottom.
- centreScreen <- (0@0).
- origin <- (0@0).
- centreScreen x: ((maxW / 2) truncated).
- centreScreen y: ((maxH / 2) truncated).
- origin <- centreScreen - (170@200).
- maxW <- 340 min: ((origin x) + (maxW - 70)).
- maxH <- 200 min: ((origin y) + (maxH - 70)).
- iWindow <- Window new;
- title: aTitle;
- openAt: origin withSize: (maxW@maxH).
- self makePanes
- |
- makePanes | ww wh ph pw |
- ww <- (iWindow size) x.
- wh <- (iWindow size) y.
- pw <- (ww / 2) truncated.
- namePane <- ListPane new;
- boundsFrom: (-1 @ -1) to: (pw @ (wh + 1));
- attachTo: iWindow withSizing: (0 @ 1).
- namePane font: 'geneva'; fontSize: 9; typeFace: 2.
- valuePane <- TextPane new;
- boundsFrom: ((pw - 1) @ -1) to: ((ww + 1) @ (wh + 1));
- attachTo: iWindow withSizing: (1 @ 1).
- valuePane font: 'monaco'; fontSize: 9.
- |
- createListFrom: theInspectedObject
- ^ nil
- |
- refreshNamePane: theInspectedObject
- namePane list: (self createListFrom: theInspectedObject); setText
- |
- makeNamePanePopMenu
- ^ nil
- |
- selectName: aKey
- ^ nil
- |
- changeValue
- ^ nil
- ]
-
- Methods ObjectInspector 'all'
- inspect: anObject
- theObject <- anObject.
- self makeNamePanePopMenu.
- self makeValuePanePopMenu.
- self makeWindow: 'Instance of: ' , ((anObject class) printString).
- namePane button1Action: [:p | valuePane clearAllText ];
- button2Action: [:p | namePMenu popUpAt: p ];
- button1DoubleClick: [:p | self selectName: (namePane getSelectedItem)].
- valuePane button2Action: [:p | valuePMenu popUpAt: p ].
- self refreshNamePane: anObject
- |
- createListFrom: anObject
- | varNames t j a |
- nameList <- List new.
- j <- anObject basicSize.
- t <- anObject class.
- [t notNil] whileTrue: [
- varNames <- t variables.
- (varNames notNil) ifTrue: [
- varNames reverseDo: [:varName |
- a <- Array new: 2; at: 1 put: (anObject basicAt: j); at: 2 put: j.
- nameList addFirstLink: (Link new;
- value: a;
- key: (varName asString)).
- j <- j - 1
- ]
- ].
- nameList addFirstLink: (Link new; value: nil;
- key: ('=== ' , (t printString) , ' ===') ).
- t <- t superClass
- ].
- ^ nameList
- |
- makeNamePanePopMenu | i |
- namePMenu <- PopUpMenu new; create.
- namePMenu addItem: 'Inspect'
- action: [
- i <- namePane getSelectedItem.
- i notNil ifTrue: [
- (i at: 1) inspect
- ]
- ];
- addItem: 'Inspect Class Hierarchy'
- action: [ (theObject class) inspect ]
- |
- makeValuePanePopMenu
- valuePMenu <- PopUpMenu new; create.
- valuePMenu addItem: 'Accept'
- action: [ self changeValue ];
- addItem: 'Cancel'
- action: [ self cancel ].
- |
- selectName: aValue
- (aValue notNil) ifTrue: [
- valuePane clearAllText.
- valuePane print: ((aValue at: 1) printString).
- valuePMenu enableItem: 1; enableItem: 2
- ]
- ifFalse: [
- valuePMenu disableItem: 1; disableItem: 2
- ]
- |
- changeValue
- | valueArray s |
- valueArray <- namePane getSelectedItem.
- (valueArray notNil) ifTrue: [
- inspectorTemp001 <- theObject.
- s <- 'inspectorTemp001 basicAt: ' ,
- (valueArray at: 2) printString ,
- ' put: ' , (valuePane text).
- [
- (s execute) notNil ifTrue: [
- valueArray
- at: 1
- put: (inspectorTemp001 basicAt: (valueArray at: 2))
- ]
- ] fork
- ]
- |
- cancel
- valuePane clearAllText.
- valuePMenu disableItem: 1; disableItem: 2
- ]
-
- Methods ClassHierarchyInspector 'all'
- inspect: aClass
- theClass <- aClass.
- self makeNamePanePopMenu.
- self makeValuePanePopMenu.
- self makeWindow: 'Class: ' , (aClass printString).
- namePane button1Action: [:p | valuePane clearAllText ];
- button2Action: [:p | p <- nil ].
- namePane button1DoubleClick: [:p | self selectName: (namePane getSelectedItem) ].
- valuePane button2Action: [:p | valuePMenu popUpAt: p ].
- self refreshNamePane: aClass
- |
- createListFrom: aClass
- | classList dots |
- classList <- List new.
- aClass upSuperclassChain: [:c |
- classList addFirstLink: (Link new;
- value: c;
- key: (c printString) )
- ].
- dots <- ''.
- classList newDo: [ :lk |
- lk key: (dots , (lk key)).
- dots <- (dots , '..')
- ].
- ^ classList
- |
- makeNamePanePopMenu
- ^ nil
- |
- makeValuePanePopMenu
- valuePMenu <- PopUpMenu new; create.
- valuePMenu addItem: 'Add Variables'
- action: [ self addVariables ];
- addItem: 'Remove Variables'
- action: [ self removeVariables ];
- addItem: 'Cancel'
- action: [ self cancel ].
- |
- selectName: aClass | v |
- v <- aClass variables.
- valuePane clearAllText.
- (v isNil) ifTrue: [
- valuePane print: '<No instance variables>'.
- valuePMenu enableItem: 1; disableItem: 2; enableItem: 3
- ]
- ifFalse: [
- v do: [:c | valuePane print: (c asString) , newLine ].
- valuePMenu enableItem: 1; enableItem: 2; enableItem: 3
- ].
- selectedClass <- aClass
- |
- addVariables | a |
- a <- (valuePane text) words: [:x | x isAlphaNumeric ].
- a do: [ :x | selectedClass addInstanceVariable: (x asSymbol) ].
- self selectName: selectedClass
- |
- removeVariables | a r |
- a <- (valuePane selectedText) words: [:x | x isAlphaNumeric ].
- r <- smalltalk inquire: 'Please confirm removal of ',
- (a size) asString, ' variables'.
- (r isNil) ifFalse: [
- r ifTrue: [
- a do: [ :x | selectedClass removeInstanceVariable: (x asSymbol) ]
- ]
- ].
- self selectName: selectedClass
- |
- cancel
- valuePane clearAllText.
- valuePMenu disableItem: 1; disableItem: 2
- ]
-
- Methods CollectionInspector 'all'
- inspect: aCollection
- theCollection <- aCollection.
- self makeNamePanePopMenu.
- self makeValuePanePopMenu.
- self makeWindow: 'Collection: ' , (aCollection class printString).
- namePane button1Action: [:p | valuePane clearAllText ];
- button2Action: [:p | namePMenu popUpAt: p ].
- namePane button1DoubleClick: [:p | self selectName: (namePane getSelectedItem) ].
- valuePane button2Action: [:p | valuePMenu popUpAt: p ].
- self refreshNamePane: aCollection
-
- |
- createListFrom: aCollection | theList a l |
- theList <- List new.
- aCollection binaryDo: [:k :v |
- l <- Link new.
- a <- Array new: 3; at: 1 put: v; at: 2 put: k; at: 3 put: l.
- l value: a; key: ((k printString) , ' -> ' , (v printString)).
- theList addLastLink: l
- ].
- ^ theList
- |
- makeNamePanePopMenu | i |
- namePMenu <- PopUpMenu new; create.
- namePMenu addItem: 'Inspect'
- action: [
- i <- namePane getSelectedItem.
- i notNil ifTrue: [
- (i at: 1) inspect
- ]
- ];
- addItem: 'Add Key'
- action: [ self addKey ];
- addItem: 'Remove Key'
- action: [ self removeKey ]
- |
- makeValuePanePopMenu
- valuePMenu <- PopUpMenu new; create.
- valuePMenu addItem: 'Accept'
- action: [ self changeValue ];
- addItem: 'Cancel'
- action: [ self cancel ].
- |
- selectName: aValue
- aValue notNil ifTrue: [
- valuePane clearAllText.
- valuePane print: ((aValue at:1) printString).
- valuePMenu enableItem: 1; enableItem: 2
- ]
- ifFalse: [
- valuePMenu disableItem: 1; disableItem: 2
- ]
- |
- executeAnAt: atText withPut: putText
- | s |
- inspectorTemp001 <- theCollection.
- s <- 'inspectorTemp001 at: ', atText, ' put: ', putText.
- ^ (s execute)
- |
- addKey
- | ky |
- ky <- smalltalk getPrompt: 'Enter a key:'.
- (ky ~= '') ifTrue: [
- [
- (self executeAnAt: ky withPut: 'nil') notNil
- ifTrue: [
- self refreshNamePane: theCollection
- ]
- ] fork
- ]
- |
- removeKey
- | valueArray r |
- valueArray <- namePane getSelectedItem.
- (valueArray notNil) ifTrue: [
- r <- smalltalk inquire: ('Please confirm removal of item ',
- ((valueArray at: 2) asString) ).
- (r isNil) ifFalse: [
- r ifTrue: [
- theCollection removeKey: (valueArray at: 2).
- self refreshNamePane: theCollection.
- valuePane clearAllText
- ]
- ]
- ]
- |
- changeValue
- | valueArray |
- valueArray <- namePane getSelectedItem.
- (valueArray notNil) ifTrue: [
- [
- (self executeAnAt: ((valueArray at: 2) printString)
- withPut: (valuePane text))
- notNil ifTrue: [
- self refreshNamePane: theCollection
- ]
- ] fork
- ]
- |
- cancel
- valuePane clearAllText.
- valuePMenu disableItem: 1; disableItem: 2
- ]
-
- Methods ArrayInspector 'all'
- addKey
- theCollection <- (theCollection grow: nil).
- self refreshNamePane: theCollection
- |
- removeKey
- | valueArray r |
- valueArray <- namePane getSelectedItem.
- (valueArray notNil) ifTrue: [
- r <- smalltalk inquire: ('Please confirm removal of item ',
- ((valueArray at: 2) asString) ).
- (r isNil) ifFalse: [
- r ifTrue: [
- theCollection removeValues: [ :y | y = (valueArray at: 1) ].
- self refreshNamePane: theCollection.
- valuePane clearAllText
- ]
- ]
- ]
- ]